import Vue from 'vue'
import VueRouter from 'vue-router'

const Home = () =>
  import('../views/home/Home.vue')
const HomeAbnormal = () =>
  import('../views/home/homeViews/HomeAbnormal.vue')
const HomeCommend = () =>
  import('../views/home/homeViews/HomeCommend.vue')
const HomeDiscount = () =>
  import('../views/home/homeViews/HomeDiscount.vue')
const HomeWeb = () =>
  import('../views/home/homeViews/HomeWeb.vue')
const Game = () =>
  import('../views/game/Game.vue')
const Rebate = () =>
  import('../views/rebate/Rebate.vue')
const Stored = () =>
  import('../views/stored/Stored.vue')
const Mine = () =>
  import('../views/mine/Mine.vue')
const Custom = () =>
  import('../views/custom/Custom.vue')
const HelpFeedBack = () =>
  import('../views/custom/help/HelpFeedBack.vue')
const HelpStored = () =>
  import('../views/custom/help/HelpStored.vue')
const HelpAccount = () =>
  import('../views/custom/help/HelpAccount.vue')
const HelpOther = () =>
  import('../views/custom/help/HelpOther.vue')
const Search = () =>
  import('../views/search/Search.vue')
const RebateHelp = () =>
  import('../views/rebate/help/RebateHelp.vue')
const ServerMessage = () =>
  import('../views/mine/server/ServerMessage.vue')
const ServerRecharge = () =>
  import('../views/mine/server/ServerRecharge.vue')
const ServerNotice = () =>
  import('../views/mine/server/ServerNotice.vue')
const ServerMineGame = () =>
  import('../views/mine/server/ServerMineGame.vue')
const ServerCoupon = () =>
  import('../views/mine/server/ServerCoupon.vue')
const ServerCard = () =>
  import('../views/mine/server/ServerCard.vue')
const ServerFeedback = () =>
  import('../views/mine/server/ServerFeedback.vue')
const SetUp = () =>
  import('../views/mine/setup/SetUp.vue')
const CodeExchangeRecord = () =>
  import('../views/mine/childComps/code/CodeExchangeRecord.vue')
const PointsMall = () =>
  import('../views/mine/childComps/code/PointsMall.vue')
const MemberCenter = () =>
  import('../views/member/MemberCenter.vue')
const BuyMember = () =>
  import('../views/member/BuyMember.vue')
const Detail = () =>
  import('../views/detail/Detail.vue')
const CouponDetail = () =>
  import('../views/detail/coupon/CouponDetail.vue')
const BindingMobilePhone = () =>
  import('../views/mine/setup/childComps/BindingMobilePhone.vue')
const ChangePassword = () =>
  import('../views/mine/setup/childComps/ChangePassword.vue')
const RealName = () =>
  import('../views/mine/setup/childComps/RealName.vue')
const AntiAddiction = () =>
  import('../views/mine/setup/childComps/AntiAddiction.vue')
const Login = () =>
  import('../views/login/Login.vue')
const ForgetPassword = () =>
  import('../views/login/childComps/ForgetPassword.vue')
const PrivacyAgreement = () =>
  import('../views/login/agreement/PrivacyAgreement.vue')
const UserAgreement = () =>
  import('../views/login/agreement/UserAgreement.vue')
const PreferredCoupon = () =>
  import('../views/home/page/PreferredCoupon.vue')
const AccountTransaction = () =>
  import('../views/home/page/AccountTransaction.vue')
const ServiceOpenTable = () =>
  import('../views/home/page/ServiceOpenTable.vue')
const TransactionSell = () =>
  import('../views/home/page/transaction/TransactionSell.vue')
const TransactionMine = () =>
  import('../views/home/page/transaction/TransactionMine.vue')
const GoodsDetail = () =>
  import('../views/home/page/goods/GoodsDetail.vue')
const RebateApplyInfo = () =>
  import('../views/rebate/rebateInfo/RebateApplyInfo.vue')

Vue.use(VueRouter)

// 解决Vue-Router升级导致的Uncaught(in promise) navigation guard问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
// 解决Vue-Router升级导致的Uncaught(in promise) navigation guard问题
const originalReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace(location, onResolve, onReject) {
  if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

const routes = [{
  path: '/',
  redirect: '/home',
}, {
  path: '/home',
  component: Home,
  meta: {
    isturn: true
  },
  children: [{
    path: '/home', //首页
    redirect: '/home/commend',
  }, {
    path: '/home/abnormal',
    component: HomeAbnormal,
    meta: {
      isturn: true
    }
  }, {
    path: '/home/commend',
    component: HomeCommend,
    meta: {
      isturn: true
    }
  }, {
    path: '/home/discount',
    component: HomeDiscount,
    meta: {
      isturn: true
    }
  }, {
    path: '/home/web',
    component: HomeWeb,
    meta: {
      isturn: true
    }
  }]
}, {
  path: '/game', //游戏
  component: Game,
  meta: {
    isturn: true
  },
}, {
  path: '/rebate', //返利
  component: Rebate,
  meta: {
    isturn: false
  },
}, {
  path: '/stored', //储值
  component: Stored,
  meta: {
    isturn: false
  },
}, {
  path: '/mine', //我的
  component: Mine,
  meta: {
    isturn: true
  },
}, {
  path: '/custom_center', //客服中心
  component: Custom,
  meta: {
    isturn: false
  },
}, {
  path: '/kefuhelp/typeid/1', //回馈帮助
  component: HelpFeedBack,
  meta: {
    isturn: false
  },
}, {
  path: '/kefuhelp/typeid/2', //储值帮助
  component: HelpStored,
  meta: {
    isturn: false
  },
}, {
  path: '/kefuhelp/typeid/3', //账号安全
  component: HelpAccount,
  meta: {
    isturn: false
  },
}, {
  path: '/kefuhelp/typeid/4', //其他帮助
  component: HelpOther,
  meta: {
    isturn: false
  },
}, {
  path: '/search', //搜索页
  component: Search,
  meta: {
    isturn: false
  },
}, {
  path: '/rebate/help', //搜索页
  component: RebateHelp,
  meta: {
    isturn: false
  },
}, {
  path: '/userinfo/message', //我的消息
  component: ServerMessage,
  meta: {
    isturn: false
  },
}, {
  path: '/userinfo/recharge', //充值明细
  component: ServerRecharge,
  meta: {
    isturn: false
  },
}, {
  path: '/userinfo/notice', //公告
  component: ServerNotice,
  meta: {
    isturn: false
  },
}, {
  path: '/userinfo/game', //我的游戏
  component: ServerMineGame,
  meta: {
    isturn: false
  },
}, {
  path: '/userinfo/coupon', //我的礼券
  component: ServerCoupon,
  meta: {
    isturn: false
  },
}, {
  path: '/userinfo/card', //我的礼包
  component: ServerCard,
  meta: {
    isturn: false
  },
}, {
  path: '/userinfo/Feedback', //意见反馈
  component: ServerFeedback,
  meta: {
    isturn: false
  },
}, {
  path: '/userinfo/setup', //意见反馈
  component: SetUp,
  meta: {
    isturn: false
  },
}, {
  path: '/userinfo/code_record', //激活码兑换记录
  component: CodeExchangeRecord,
  meta: {
    isturn: false
  },
}, {
  path: '/userinfo/pointsmall', //积分商城
  component: PointsMall,
  meta: {
    isturn: false
  },
}, {
  path: '/userinfo/member_center', //会员中心
  component: MemberCenter,
  meta: {
    isturn: false
  },
}, {
  path: '/vip_pay_page/:iid', //购买会员支付页
  component: BuyMember,
  meta: {
    isturn: false
  },
}, {
  path: '/gameinfo/gameid/:iid', //游戏详情页
  component: Detail,
  meta: {
    isturn: false
  },
}, {
  path: '/gameinfo/coupon', //游戏详情页
  component: CouponDetail,
  meta: {
    isturn: false
  },
}, {
  path: '/user_bound_mobile', //绑定手机
  component: BindingMobilePhone,
  meta: {
    isturn: false
  },
}, {
  path: '/user_modify_pwd', //修改密码
  component: ChangePassword,
  meta: {
    isturn: false
  },
}, {
  path: '/user_idcard_add', //实名认证
  component: RealName,
  meta: {
    isturn: false
  },
}, {
  path: '/anti_addiction', //防沉迷
  component: AntiAddiction,
  meta: {
    isturn: false
  },
}, {
  path: '/login', // 登录
  component: Login,
  meta: {
    isturn: false
  },
}, {
  path: '/login/forget_password', // 忘记密码
  component: ForgetPassword,
  meta: {
    isturn: false
  },
}, {
  path: '/login/privacy_agreement', // 隐私协议
  component: PrivacyAgreement,
  meta: {
    isturn: false
  },
}, {
  path: '/login/user_agreement', // 用户协议
  component: UserAgreement,
  meta: {
    isturn: false
  },
}, {
  path: '/preferred_coupon', // 优选好券
  component: PreferredCoupon,
  meta: {
    isturn: false
  },
}, {
  path: '/account_transaction', // 账号交易
  component: AccountTransaction,
  meta: {
    isturn: false
  },
}, {
  path: '/service_open_table', // 开服表
  component: ServiceOpenTable,
  meta: {
    isturn: false
  },
}, {
  path: '/transaction_sell', // 卖号
  component: TransactionSell,
  meta: {
    isturn: false
  },
},{
  path: '/transaction_mine', // 我的交易
  component: TransactionMine,
  meta: {
    isturn: false
  },
},{
  path: '/goods/gameinfo/gameid', // 交易商品详情
  component: GoodsDetail,
  meta: {
    isturn: false
  },
},{
  path: '/rebate_apply_info/apply_id/:iid', // 返利成功失败
  component: RebateApplyInfo,
  meta: {
    isturn: false
  },
},
]

const router = new VueRouter({
  routes
})

export default router
